package sensorframework.client;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;

import sensorframework.client.structuur.Sensor;
import sensorframework.client.structuur.Sensors;



public class SensorFrameworkClient {

	
	
	public void SensorFrameworkClient()
	{
		
	}
	
	

	
	/**
	 * Covert xml to sensor Object
	 * @param xmlLocation
	 * @return create sensor object
	 */
	public Sensors convertXMLtoSensors(String xmlLocation)
	{
			Sensors sensors = null;
			try {
			File file = new File(xmlLocation);
			
			JAXBContext jaxbContext = JAXBContext.newInstance(Sensors.class);
			Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
			sensors = (Sensors) jaxbUnmarshaller.unmarshal(file);
			
			} catch (Exception e){ 
				e.printStackTrace();
			} 
			return sensors;
	}
	
	public Sensor convertXMLtoSensor(String xmlLocation) {
		
		Sensor sensor = null;
		try {
		File file = new File(xmlLocation);
		
		JAXBContext jaxbContext = JAXBContext.newInstance(Sensor.class);
		Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
		sensor = (Sensor) jaxbUnmarshaller.unmarshal(file);
		
		} catch (Exception e){ 
			e.printStackTrace();
		} 
		return sensor;
	}
	
	public  void saveDataToFile(byte[] data, String file)
	{
		try {
	 		BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
				
		 		bos.write(data);
		 		bos.flush();
		 		bos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}




	
}
